package com.lineage.william;

import com.lineage.DatabaseFactory;
import com.lineage.server.datatables.RecordTable;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;

public class PayBonus {
  public static void getItem(L1PcInstance pc, int count) {
    Connection conn = null;
    try {
      conn = DatabaseFactory.get().getConnection();
      Statement stat = conn.createStatement();
      ResultSet rs = stat.executeQuery("SELECT * FROM ezpay_满额送礼");
      ArrayList<?> arraylist = null;
      if (rs != null)
        while (rs.next()) {
          Timestamp now_time = new Timestamp(System.currentTimeMillis());
          int min_money = rs.getInt("min_money");
          int max_money = rs.getInt("max_money");
          int itemid = rs.getInt("give_item");
          int itemcount = rs.getInt("give_count");
          Timestamp end_time = rs.getTimestamp("限制结束时间");
          if (end_time != null && now_time.after(end_time))
            continue; 
          if (count < min_money || count > max_money)
            continue; 
          L1ItemInstance items = pc.getInventory().storeItem(itemid, itemcount);
          pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fW获得赞助满额好礼:" + items.getName() + "(" + itemcount + ")"));
          RecordTable.get().recordeSponsorItem(pc.getAccountName(), pc.getName(), max_money, pc.getIp());
        }  
      if (conn != null && !conn.isClosed())
        conn.close(); 
    } catch (Exception exception) {}
  }
}
